#include "OutputTag.h"
#include <iostream>
using namespace std;

OutputTag :: OutputTag(QWidget* parent, int _code, QString* text) : QTextBrowser(parent), Tag(_code), numRow(text->count('\n')+2), fontSize(17) {
	QFont font("Helvetica");
	font.setPixelSize(fontSize);
	setFont(font);
	setFontPointSize(fontSize);
	setHtml(*text);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setAutoFillBackground(true);
	QPalette p;
	p.setColor(QPalette::Base, QColor(207,203,250));
	setPalette(p);
	setFrameStyle(QFrame::Plain|QFrame::Panel);
	setBackgroundRole(QPalette::Base);
	document()->adjustSize();
	document()->setTextWidth(-1);
	resetDimension();
}

void OutputTag :: setText(QString* text) {
	numRow = text->count('\n')+1;
	document()->setHtml(*text);
	document()->adjustSize();
	QFont font("Helvetica");
	font.setPixelSize(fontSize);
	setFont(font);
	setFontPointSize(fontSize);
	document()->setTextWidth(-1);
	setMinimumSize(300, document()->documentLayout()->documentSize().height()+5);
	setMaximumSize(2000, document()->documentLayout()->documentSize().height()+5);
}

int OutputTag :: height() {
	return 2*fontPointSize()*(toPlainText().count('\n')+1);
}

void OutputTag :: setFontSize(int size) {
	fontSize = size;
	QFont font("Helvetica");
	font.setPointSize(fontSize);
	setCurrentFont(font);
}

void OutputTag :: resetDimension() {
	setMinimumSize(300,  document()->documentLayout()->documentSize().height()+5);
	setMaximumSize(2000, document()->documentLayout()->documentSize().height()+5);
}
